function forEach(collection, func) {
    for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
        func(e.item());
    }
}

function toObject(item) {
    var obj = {};
    forEach(item.Properties_, function (p) {
        var name = p.Name;
        var val = item[name];
        obj[name] = val;
    });
    return obj;
}

function wmi(sql) {
    var locator = new ActiveXObject('WbemScripting.SWbemLocator');
    var service = locator.ConnectServer('.');
    var properties = service.ExecQuery(sql);
    var e = new Enumerator(properties);
    var arr = [];
    for (; !e.atEnd(); e.moveNext()) {
        arr.push(toObject(e.item()));
    }
    return JSON.stringify(arr);
}
